/*
============================================================================
 Name        : BaseCommon.cpp
 Author      : \x{738b}\x{658c}
 Version     :
 Copyright   : \x{76ca}\x{76df}\x{8f6f}\x{4ef6}
 Description : CBaseCommon implementation
============================================================================
*/

#include "BaseCommon.h"
#include <eikenv.h>
//#include <aknutils.h>
#include "Global.h"
#include "eStockappui.h"
#include "ThreadSocket.h"
#include "Control.h"
#include "keyboard.h"
#include "eStockMainGridContainer.h"
#include "Block.h"
#include "Logger.h"
#include <eStock_L2hy.rsg>
#include "Toolbar.h"
#include "Tabbar.h"
#include "Titlebar.h"
#include "ImageTool.h"

_LIT(KHostUrl,"http://mobile.emoney.cn:80");

CBaseCommon::CBaseCommon():
m_nCountSocket(0),
m_nSecondCount(0),
m_nOnlineDays(0),
m_bShowKB(EFalse)
{
}

CBaseCommon::~CBaseCommon()
{
	if (iToolbar != NULL)
		delete iToolbar, iToolbar = NULL;

	if (iTabbar != NULL)
		delete iTabbar, iTabbar = NULL;

	if (iTitlebar != NULL)
		delete iTitlebar, iTitlebar = NULL;

	if (iUparrowBitmap)
		delete iUparrowBitmap, iUparrowBitmap = NULL;
	if (iUparrowBitmapmask)
		delete iUparrowBitmapmask, iUparrowBitmapmask = NULL;
	if (iDownarrowBitmap)
		delete iDownarrowBitmap, iDownarrowBitmap = NULL;
	if (iDownarrowBitmapmask)
		delete iDownarrowBitmapmask, iDownarrowBitmapmask = NULL;
	if (iLeftarrowBitmap)
		delete iLeftarrowBitmap, iLeftarrowBitmap = NULL;
	if (iLeftarrowBitmapmask)
		delete iLeftarrowBitmapmask, iLeftarrowBitmapmask = NULL;
	if (iRightarrowBitmap)
		delete iRightarrowBitmap, iRightarrowBitmap = NULL;
	if (iRightarrowBitmapmask)
		delete iRightarrowBitmapmask, iRightarrowBitmapmask = NULL;
	
	delete m_kb;
}

CBaseCommon* CBaseCommon::Static()
{
	CBaseCommon* base = (STATIC_CAST(CeStockAppUi*,CEikonEnv::Static()->AppUi()))->m_BaseCommon;
	return base;
}

CBaseCommon* CBaseCommon::NewLC()
{
	CBaseCommon* self = new (ELeave)CBaseCommon();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
}

CBaseCommon* CBaseCommon::NewL()
{
	CBaseCommon* self=CBaseCommon::NewLC();
	CleanupStack::Pop(); // self;
	return self;
}

void CBaseCommon::ConstructL()
{
	m_strURL.Copy(KHostUrl);

	//m_stockInput = CStockTextInput::NewL();
	//m_threadSocket = CThreadSocket::NewL();
	//m_threadSocketInfo = CThreadSocket::NewL();
	m_kb = CKeyBoard::NewL();

	iUparrowBitmap = new (ELeave) CFbsBitmap;
	iUparrowBitmapmask = new (ELeave) CFbsBitmap;
	CImageTool::CreateFbsBmpFromPng(_L("uparrow.png"), iUparrowBitmap, iUparrowBitmapmask);

	iDownarrowBitmap = new (ELeave) CFbsBitmap;
	iDownarrowBitmapmask = new (ELeave) CFbsBitmap;
	CImageTool::CreateFbsBmpFromPng(_L("downarrow.png"), iDownarrowBitmap, iDownarrowBitmapmask);

	iLeftarrowBitmap = new (ELeave) CFbsBitmap;
	iLeftarrowBitmapmask = new (ELeave) CFbsBitmap;
	CImageTool::CreateFbsBmpFromPng(_L("leftarrow.png"), iLeftarrowBitmap, iLeftarrowBitmapmask);

	iRightarrowBitmap = new (ELeave) CFbsBitmap;
	iRightarrowBitmapmask = new (ELeave) CFbsBitmap;
	CImageTool::CreateFbsBmpFromPng(_L("rightarrow.png"), iRightarrowBitmap, iRightarrowBitmapmask);

	iToolbar = CToolbar::NewL();
	iTabbar = CTabbar::NewL();
	iTitlebar = CTitlebar::NewL();
}

//#ifdef __SERIES60_3X__
//void CBaseCommon::SetLogoSize()
//{
//	if (m_imageLogo != NULL && m_imageLogoMask != NULL)
//	{
//		CGlobal* globe = (STATIC_CAST(CeStockAppUi*,CEikonEnv::Static()->AppUi()))->m_Globe;
//		// Set size for the bitmap and mask
//		AknIconUtils::SetSize(m_imageLogo, TSize(globe->g_nFontHeight, globe->g_nFontHeight));
//		AknIconUtils::SetSize(m_imageLogoMask, TSize(globe->g_nFontHeight, globe->g_nFontHeight));
//	}
//}
//#endif
